package com.hnxxxy.jfmgr.service.Impl;

import com.hnxxxy.common.AjaxRtnEntity.AjaxRtnEntity;
import com.hnxxxy.jfmgr.mapper.JfUserTestimonialsStatusMapper;
import com.hnxxxy.jfmgr.pojo.Jf_detail;
import com.hnxxxy.jfmgr.service.JfUserTestimonialsStatusService;
import com.hnxxxy.sysmgr.pojo.Staff;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.util.List;

@Service
@Slf4j
public class JfUserTestimonialsStatusServiceImpl implements JfUserTestimonialsStatusService {

    @Autowired
    JfUserTestimonialsStatusMapper jfUserTestimonialsStatusMapper;

    @Override
    public List<Jf_detail> findAlUserTestimonialsStatus(Jf_detail jf_detail) {
        Subject subject = SecurityUtils.getSubject();
        Staff staff = (Staff) subject.getPrincipal();
        jf_detail.setUserId(staff.getUserid());
        return jfUserTestimonialsStatusMapper.findAlUserTestimonialsStatus(jf_detail);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public int deleteUserTestimonialsStatus(Integer[] ids) {
        try {
            for (int i = 0; i < ids.length; i++) {
                jfUserTestimonialsStatusMapper.deleteUserTestimonialsStatus(ids[i]);
                jfUserTestimonialsStatusMapper.deleteUserTestimonialsAttachment(ids[i]);
            }
            return AjaxRtnEntity.success;
        } catch (Exception e) {
            log.info("-->用户奖状上传状态删除异常：" + e.toString());
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return AjaxRtnEntity.error;
        }
    }
}
